package com.suxin.thread.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * @author Tang
 * @classname ListenableFuture
 * @description [  ]
 * @date 2023/2/7 11:29
 */
public interface ListenableFuture<V> extends Future<V> {

    public void addCallback(ListenableFutureCallback<V> callback);

    public void addCallback(SuccessCallback<V> successCallback, FailureCallback failureCallback);

    default CompletableFuture<V> completable() {
        CompletableFuture<V> completableFuture = new CompletableFuture<>();
        addCallback(completableFuture::complete,completableFuture::completeExceptionally);
        return completableFuture;
    }
}